<template>
  <div class='container'>
    <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <el-button
          style="float:right"
          type="primary"
          size="small"
          @click="search_button()">
          查询搜索
        </el-button>
        <el-button
          style="float:right;margin-right: 15px"
          size="small"
          @click="reset_button()">
          重置
        </el-button>
      </div>
      <div style="margin-top: 15px">
        <el-form :inline="true"  size="small" label-width="140px">
          <el-form-item label="输入搜索：">
            <el-input  class="input-width" v-model="keyword_value" placeholder="店长" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>店长列表</span>
      <el-button size="mini" class="btn-add" @click="multiple_delete_button()" style="margin-left: 20px; float:right" icon='el-icon-delete' type="danger">批量删除</el-button>
      <el-button size="mini" class="btn-add" @click="add_button()" style="margin-left: 20px; float:right" icon='el-icon-plus' type="primary">添加</el-button>
    </el-card>
    <div class='table-container'>
      <el-table
        class='m-30-t'
        :data="experts_list"
        fit
        stripe
        v-loading="listLoading"
        @select="chosen_option"
        @select-all="all_options"
        border
        highlight-current-row>
        <el-table-column type="selection" ></el-table-column>
        <el-table-column
          prop="id"
          label="店长id"
          align="left">
        </el-table-column>
        <el-table-column
          prop="name"
          label="店长姓名"
          align="center">
        </el-table-column>
        <el-table-column
          prop="phone"
          label="店长电话"
          align="center">
        </el-table-column>
        <el-table-column
          prop="recommend_id"
          label="上级店长"
          align="center">
          <template slot-scope="scope">
            <div class="">
              <span v-if="scope.row.recommend_id==0">无</span>
              <span v-else>上级店长id:{{scope.row.recommend_id}}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="店长uid"
          align="center">
          <template slot-scope="scope">
            <div class="">
              <span v-if="scope.row.uid==0">未绑定</span>
              <span v-else>{{scope.row.uid}}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="description"
          label="店长描述"
          align="center">
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          width="300px">
          <template slot-scope="scope">
            <div>
              <el-button size="mini" type="warning" @click="detail_button(scope.row.id)">详情</el-button>
              <el-button size="mini" type="danger" @click="delete_button(scope.row.id)">删除</el-button>
              <el-button size="mini" type="success" @click="edit_button(scope.$index, scope.row)">编辑</el-button>
            </div>
            <div style='height: 20px'>
            </div>
            <div>
              <el-button size="small" type="success" @click="online_recharge_button(scope.row.uid)">充值</el-button>
              <el-button size="small" type="primary" @click="point_button(scope.row.uid)">积分</el-button>
              <el-button size="mini" type="warning" @click="shop_member_button(scope.row.id)">门店</el-button>
            </div>

          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container m-50-t m-50-b">
      <span></span>
      <el-pagination
        background
        @size-change="size_change"
        @current-change="current_change"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="page_num"
        :page-size="page_size"
        :page-sizes="page_sizes"
        :total="total">
      </el-pagination>
    </div>
    <el-dialog
      :title="isEdit?'编辑':'添加'"
      :visible.sync="dialog_visible"
      width="40%">
      <el-form 
               ref="adminForm"
               label-width="150px" size="small">
        <el-form-item   label="店长姓名：">
          <el-input style="width: 250px" v-model="name"></el-input>
        </el-form-item>
        <el-form-item label="店长称号：">
          <el-input style="width: 250px" v-model="jobTitle"></el-input>
        </el-form-item>
        <el-form-item label="店长描述：">
          <el-input style="width: 250px" v-model="description"></el-input>
        </el-form-item>
        <!-- <el-form-item label="生日：">
          <el-input  type="password" style="width: 250px" v-model="birthday"></el-input>
        </el-form-item> -->
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialog_visible = false" size="small">取 消</el-button>
        <el-button type="primary" size="small" @click="confirm_button">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog 
      title="店长详情" 
      width="50%"
      :visible.sync="detail_dialog_visible">
      <div>
        <span class="title">店长姓名：</span>
        <span class="m-10-l ">{{detail_data.name}}</span>
      </div>
      <div class=' m-30-t'>
        <span class="title">店长称号：</span>
        <span class="m-10-l  ">{{detail_data.jobTitle}}</span>
      </div>
      <div class=' m-30-t'>
        <span class="title">店长描述：</span>
        <span class="m-10-l  ">{{detail_data.description}}</span>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="detail_dialog_visible = false" size="small">取 消</el-button>
        <el-button @click="detail_dialog_visible = false" type="primary" size="small">确 定</el-button>
      </span>      
    </el-dialog>

  </div>
</template>

<script>
  import experts_request from "@/api/experts_request"
  export default {
    name: 'experts_grade_eleven',
    data() {
      return {
        detail_data: {},
        experts_list: [],
        dialog_visible: false,
        isEdit: false,
        search_value: '',
        page_num: 1,
        page_size: 10,
        page_sizes: [5,10,15],
        total: null,
        name: '',
        jobTitle: '',
        birthday: '',
        description: '',
        detail_dialog_visible: false,
        keyword: '',
        keyword_value: '',
        current_size: 10,
        listLoading: false,
        current_page: 1,
      }
    },
    created() {
      this.get_list()
    },
    mounted() {
  
    },
    methods: {
      // 搜索
      search_button() {
        this.current_page = 1
        this.keyword = this.keyword_value
        this.get_list()
      },
      // 重置
      reset_button() {
        this.keyword = '' 
        this.keyword_value= ''
        this.get_list()
      },
      // 添加
      add_button() {
        this.$router.push("/experts/experts_add")
      },
      // 确认
      confirm_button() {
        if (this.isEdit) {
          experts_request.edit_experts({title: this.name}, res=> {
            console.log(res, this.name)
            this.dialog_visible = false
            this.get_list()
          })
        }
        else {
          experts_request.add_experts({}, res=> {
            this.dialog_visible = false
            this.get_list()
          })
        }
      },
      // 删除
      delete_button(id) {
        this.$confirm('是否要进行删除操作?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            let params = {
              id
            }
            experts_request.delete_experts(params, res=> {
              this.get_list()
          })
        }).catch(err=>err)
      },
      point_button(id) {
        this.$router.push({path: "/user/point", query: {id}})
      },
      shop_member_button(id) {
        this.$router.push({path: "/experts/shop_member", query: {id}})
      },
      chosen_option(id_list) {
        this.delete_list = id_list
      },
      all_options(id_list) {
        this.delete_list = id_list
      },
      multiple_delete_button() {
        this.$confirm('是否要进行批量删除操作?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          for (let item of this.delete_list) {
            experts_request.delete_experts({id: item.id}, res=> {
              this.get_list()
            })
          }
          this.delete_list = []
        }).catch(err=>err)
        
      },
      // 编辑
      edit_button(index, item) {
        this.$router.push({path: "/experts/experts_edit", query: {id: item.id}})
      },
      // 详情
      detail_button(id) {
        experts_request.detail_experts({id}, res=> {
          this.detail_data = res.data
        })
        this.detail_dialog_visible = true
      },
      size_change(current_size) {
        this.current_size = current_size
        this.get_list()
      },
      current_change(current_page) {
        this.current_page = current_page
        this.get_list()
      },
      online_recharge_button(id) {
        this.$router.push({path: "/user/online_recharge", query: {id}})
      },
      filter_list() {
        experts_request.experts_list({pageSize: 1000000000, key: this.keyword}, res=> {
          this.experts_list = res.data
          this.total = res.data.length
        })    
      },
      get_list() {
        this.listLoading = true
        let params = {
          pageSize: this.current_size, 
          page: this.current_page, 
          name: this.keyword,
          grade: 11,
        }
        experts_request.experts_list(params, res=> {
          this.listLoading = false,
          this.experts_list = res.data
          this.total = res.totalRecord
        })
      },


    }
  }
</script>

<style scoped>
@import "~@/styles/layout.scss";
.table-container {
  margin-left: 30px;
}
.pagination-container {
  float: right;
}
</style>